/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.swta;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;

/**
 *
 * @author Jan Korreck
 */
public class CategoryForm extends Form {


    private RequiredTextField idField = new RequiredTextField("id");
    private RequiredTextField nameField = new RequiredTextField("name");
//    TextField maxID = new TextField("maxCatID");

    public CategoryForm(String id) {
        super(id);
        Category newCat = new Category();
        newCat.setId(CategoryManager.getInstance().getMaxID() + 1);
        this.setModel(new CompoundPropertyModel(newCat));
        this.add(idField);
        this.add(nameField);

        idField.info("" + CategoryManager.getInstance().getMaxID() + 1);
        idField.setEnabled(false);
    }

    @Override
    protected void onSubmit() {
        Category catModel = (Category) getModelObject();

        CategoryManager.getInstance().addCategory(catModel);
        this.setResponsePage(Categories.class);
    }
}
